package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.adapter.SongListAdapter;

public class LoginActivity extends AppCompatActivity {
    private Context context;
    private RecyclerView recyclerView;
    private SongListAdapter adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        context = LoginActivity.this;

        EditText edtPhone = findViewById(R.id.phone);
        EditText edtPassword = findViewById(R.id.password);

        findViewById(R.id.tv_register1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)
            {
                Intent intent = new Intent(context, RegisterActivity.class);
                startActivity(intent);
            }
        });

        TextView tvLogin = findViewById(R.id.btn_login);
        tvLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (TextUtils.isEmpty(edtPhone.getText().toString())){
                    Toast.makeText(context, "请输入电话", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(edtPassword.getText().toString())){
                    Toast.makeText(context, "请输入密码", Toast.LENGTH_SHORT).show();
                    return;
                }



                //跳转到另一个Activity
                //Context context = Login2Activity.this; context 上下文对象 /
                Intent intent = new Intent(context, MainActivity.class);

                // activity 跳转传递数据
                intent.putExtra("username", edtPhone.getText().toString());
                intent.putExtra("password", edtPassword.getText().toString());


                //startActivity(new Intent(intent));

                startActivityForResult(intent, 1);
            }
        });
    }
}